package com.example.learnvitamio

import android.os.Bundle
import android.os.PersistableBundle
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import com.example.learnvitamio.base.BaseActivity
import com.example.learnvitamio.databinding.ActivityVideoViewDemoBinding
import io.vov.vitamio.Vitamio
import io.vov.vitamio.widget.MediaController

/**
 * 1.http://vfx.mtime.cn/Video/2019/03/19/mp4/190319212559089721.mp4
 * 2.http://82.157.163.217/666.mp4
 * @Author： LJH
 * @Time： 2022/7/9
 * @description：
 */
class VideoViewDemo:BaseActivity<ActivityVideoViewDemoBinding>() {

    var path = ""

    override fun ActivityVideoViewDemoBinding.initBinding() {
        Vitamio.initialize(this@VideoViewDemo)
        if (path == ""){
            Toast.makeText(this@VideoViewDemo,"Invalid path:无效路径。",Toast.LENGTH_SHORT).show()
            return
        }else{
            mBinding.surfaceView.setVideoPath(path)
            surfaceView.setMediaController(MediaController(this@VideoViewDemo))
            surfaceView.requestFocus()
            surfaceView.setOnPreparedListener {
                it.setPlaybackSpeed(1.0f)
            }
        }
    }

    fun startPlay(view:View){
        val url = mBinding.url.text.toString()
        path = url
        if(!TextUtils.isEmpty(url)){
            mBinding.surfaceView.setVideoPath(url)
        }
    }

    fun openVideo(view:View){
        mBinding.surfaceView.setVideoPath(path)
    }
}